package com.samphanie.security.domain;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Date;

/**
 * 验证码
 *
 * @author ZSY
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class Captcha implements Serializable {
    private static final long serialVersionUID = 5673412253031449576L;

    private String uuid;
    /**
     * 验证码
     */
    private String code;
    /**
     * 过期时间
     */
    private Date expireTime;

    @JsonIgnore
    public boolean isExpired() {
        return new Date().after(expireTime);
    }

    @JsonIgnore
    public Date getExpiredTime(long expireIn) {
        return Date.from(new Date().toInstant().plusSeconds(expireIn));
    }
}
